package com.jk.controller;

import com.jk.entity.TransferRecord;
import com.jk.entity.User;
import com.jk.entity.YuEBao;
import com.jk.service.YuebaoService;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by 动物的 on 2017/12/21.
 */
@RestController
@RequestMapping("yuebao")
public class YuebaoController {
     @Autowired
     private YuebaoService yuebaoService;


    /**
     * 查询余额宝
     * @return
     */
    @GetMapping("selectYuebao")
    public YuEBao selectYuebao(HttpServletRequest request) {
      User yuebao = (User) request.getSession().getAttribute("login");
        /*String userId = yuebao.getUserId();*/
        String userId = "446c965408ed4d1cbbe32157f9bd2f32";
       YuEBao yue = yuebaoService.selectYuebao(userId);
        return yue;
    }

    /**
     * 转入（）
     * @return
     */
    @PostMapping("updateYuebao")
    public boolean updateYuebao(HttpServletRequest request,double shiftTo,String payPass){

        User yuebao = (User) request.getSession().getAttribute("login");
        /*String userId = yuebao.getUserId();*/
        /*String payPassword = yuebao.getPayPassword();*/
        String userId = "446c965408ed4d1cbbe32157f9bd2f32";
        String payPassword = "666666";
        if(payPass != null && !"".equals(payPass) && payPassword.equals(payPass)){
            return yuebaoService.updateYuebao(userId,shiftTo);
        }else{
            return false;
        }

    }

    /**
     * 转出
     * @param request
     * @param rollOut
     * @return
     */
    @PostMapping("updateZhuanchu")
    public boolean updateZhuanchu(HttpServletRequest request,double rollOut,String payPass){

        User yuebao = (User) request.getSession().getAttribute("login");
       /* String userId = yuebao.getUserId();
        String payPassword = yuebao.getPayPassword();*/

          String userId = "446c965408ed4d1cbbe32157f9bd2f32";
          String payPassword = "666666";
        if(payPass != null && !"".equals(payPass) && payPassword.equals(payPass)){
            return yuebaoService.updateZhuanchu(userId,rollOut);
        }else{
            return false;
        }

    }



    @GetMapping("getTransferRecord")
    public List getTransferRecord(HttpServletRequest request) {
        User yuebao = (User) request.getSession().getAttribute("login");
        /*String userId = yuebao.getUserId();*/
        String userId = "446c965408ed4d1cbbe32157f9bd2f32";

        List<TransferRecord> list  = yuebaoService.getTransferRecord(userId);
        System.out.println(list);
        return list;
    }

}
